<!DOCTYPE html>
<html>
<head>
    <title>攻略系列</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css"/>
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategyCatalogs.css"/>
    <link rel="stylesheet" href="/js/plugins/dialog/dialog.css"/>
    <script src="/js/plugins/jrender/jrender.js"></script>
    <script src="/js/common.js"></script>
</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="javascript:history.go(-1);">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <input class="form-control searchBtn" placeholder="搜索旅行攻略">
            </div>
        </div>
    </div>
</div>

<div class="container strategies">
    <h5 class="title">广州攻略</h5>
    <small><span>0</span>人阅读过此攻略</small>
    <div class="focus">
        <i class="fa fa-heart"><span> 0</span> 收藏</i>
        <i class="fa fa-thumbs-up"><span> 0</span> 点赞</i>
        <button class="btn">想去</button>
        <button class="btn">去过</button>
    </div>
</div>
<ul class="nav nav-pills nav-justified border border-left-0 border-top-0 border-right-0" id="pills-tab">
    <li class="nav-item ">
        <a class="nav-link active" id="pills-catalog-tab" data-toggle="pill" href="#pills-catalog">
            <span>攻略目录</span>
        </a>
    </li>
    <li class="nav-item">
        <a class="nav-link " id="pills-comment-tab" data-toggle="pill" href="#pills-comment">
            <span>骡友点评</span>
        </a>
    </li>
</ul>
<div class="tab-content " id="pills-tabContent">
    <div class="tab-pane fade show active" id="pills-catalog">
        <div class="container hot">
            <h6>大家都在看</h6>
            <!--循环遍历所有推荐的游记-->
            <div class="titles">
                <div render-loop="list">
                    <!--渲染a标签-->
                    <a render-key="list.id" render-fun="handle">
                        <button class="btn" render-html="list.title"></button>
                    </a>
                </div>
            </div>
        </div>
        <div class="catalogs">
            <div render-loop="list">

                <div class="container detail">
                    <h6 render-key="list.name" render-fun="showTitle"></h6>

                    <div render-loop="list.details">

                        <a render-key="list.details.id" render-fun="handle">
                            <button class="btn" render-html="list.details.title"></button>
                        </a>

                    </div>
                </div>

            </div>
        </div>

    </div>
    <div class="tab-pane fade " id="pills-comment">

        <div class="container tag">
            <h6>骡友标签</h6>
            <div>
                <span>价格便宜</span>
                <span>很热闹</span>
                <span>交通方便</span>
                <span>吃的很多</span>
                <span>风景优美</span>
                <span>美食很多</span>
                <span>很特别</span>
                <span>爱上这座城</span>
                <span>住宿方便</span>
                <span>刚刚</span>
            </div>
        </div>
        <hr>
        <!--//点评-->
        <div id="comment">
            <div render-loop="list">
                <div class="container row comment">
                    <div class="col-2 comment-head">
                        <a href="userProfiles.html">
                            <img class="rounded-circle"
                                 render-src="list.user.headImgUrl">
                        </a>
                    </div>
                    <div class="col comment-right">
                        <p class="authorName"><span render-html="list.user.nickName"></span></p>
                        <span class="comment-star star" render-key="list.star" render-fun="handleStar">
                        </span>
                        <span class="comment-date" render-html="list.lastCommentTime"></span>
                        <div class="comment-content">
                            <a render-key="list.id" render-fun="handle">
                                <p render-html="list.content"></p>
                            </a>
                        </div>

                        <ul class="comment-img" render-loop="list.imgs">
                            <li>
                                <img render-src="list.imgs.url">
                            </li>
                        </ul>

                        <div class="d-flex icon">
                            <a render-key="list.id" render-fun="handle">
                                <i class="fa  fa-commenting-o " style="margin-right: 10px"> 评论 </i>
                                <i class="fa fa-thumbs-o-up"> <span>0</span> </i>
                            </a>
                        </div>

                    </div>
                </div>

            </div>
        </div>
    </div>

</div>
</div>

<div class="operation">
    <button class="btn">加入旅行单</button>
    <button class="btn" id="commentBtn">点评</button>
</div>

<script>
    $(function () {
        var strategyId = getParams().id;
        // console.log(strategyId);
        //发送ajax请求获取攻略对应的分类

        $.get("/strategies/" + strategyId + "/catalogs", function (data) {
            var i = 1;
            $(".title").html(data[0].strategyTitle);
            $(".catalogs").renderValues({list: data}, {
                showTitle: function (ele, val) {
                    var content = i + "/" + val;
                    //如果i<10前面补0
                    if (i < 10) {
                        content = 0 + content;
                    }
                    i++;
                    ele.innerHTML = content;
                },
                handle: function (ele, val) {
                    ele.href = "/strategyDetails.html?id=" + val;
                }
            });
        });
        //travel/"+strategyId+"/travels/titles
        $.get("/travels/titles",{strategyId:strategyId}  , function (data) {
            $(".titles").renderValues({list: data}, {
                handle: function (ele, val) {
                    ele.href = "/travelContent.html?id=" + val;
                }
            })
        }, "json")
        /*<!--//点评-->*/
        //发送ajax请求获取当前攻略的评论
        $.get("/comments", {stratagyType: strategyId}, function (data) {
            $("#comment").renderValues(data, {
                handle: function (ele, val) {
                    ele.href = "/comment/strategyComment.html?id=" + val;
                },
                handleStar: function (ele, val) {
                    var num = val;
                    for (var i=0;i<num;i++){
                        $("<i></i>").addClass("fa-star").addClass("fa").appendTo($(ele));
                    }
                    for (var i=0;i<5-num;i++){
                        $("<i></i>").addClass("fa-star-o").addClass("fa").appendTo($(ele));
                    }
                }
            });

        });
        $("#commentBtn").click(function () {
            if (getUser()) {
                location.href = "/comment/addComment.html?id=" + strategyId;
            }else {
                location.href = "/login.html";
            }
        });
    });
</script>
</body>
</html>